/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import View.*;
import DAO.*;
import TO.AuthorTO;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author admin-pc
 */
public class AuthorController {

    private AuthorView view;
    private AuthorTO model;

    AuthorDAO daof = DAOFactory.getInstance().getAuthorDAO();

    public AuthorController(AuthorTO model) {
        this.model = model;
        view = new AuthorView(model, model, this);
    }

    public void authorAdd(String name) {
        daof.add(new AuthorTO(name));
    }

    public void authorDelete(int id) {
        daof.delete(id);
    }

    ;
    public void authorUpdate(String name, int id) {
        daof.update(new AuthorTO(name, id));
    }

    ;
    
    public void authorSelectAll() {
        List list = daof.findAll();
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            AuthorTO author = (AuthorTO) iterator.next();
            System.out.print("ID Автора: " + author.getAuthorId() + " " + "\tИмя автора: " + author.getAuthorName().trim() + "\n");
        }
    }

}
